package com.nowcoder.code.lcof;

import java.util.Stack;

public class JZ31 {

    public static void main(String[] args) {
        System.out.println(new JZ31().IsPopOrder(new int[]{1,2,3,4,5},new int[]{4,3,5,1,2}));
    }

    public boolean IsPopOrder(int[] pushV, int[] popV) {

        Stack<Integer> stack = new Stack<>();
        int j = 0, i = 0;
        for (; i < pushV.length; i++) {
            stack.push(pushV[i]);
            while (!stack.isEmpty() && stack.peek() == popV[j]) {
                stack.pop();
                j++;
            }

        }
        return stack.isEmpty();

    }
}
